package com.sangmo.fts.api.basic;

import com.sangmo.boot.framework.api.utils.ApiResponse;
import com.sangmo.boot.framework.data.filter.PageResult;
import com.sangmo.boot.framework.data.json.ExtViewHelper;
import com.sangmo.boot.framework.plugin.dataview.data.DataViewPageSearch;
import com.sangmo.fts.basic.interfaces.DocumentTemplateCreation;
import com.sangmo.fts.basic.model.DocumentTemplate;
import com.sangmo.fts.basic.service.DocumentTemplateService;
import com.sangmo.fts.teacher.model.Examination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.HashMap;

@Controller
@RequestMapping("/documentTemplate/v1")
public class DocumentTemplateApi {

    @Autowired
    private DocumentTemplateService documentTemplateService;

    @PostMapping(value = "/create")
    public @ResponseBody
    ApiResponse<DocumentTemplate> create(@RequestBody @Valid DocumentTemplateCreation obj) {
        return ApiResponse.make(documentTemplateService.create(obj));
    }

    @PostMapping("/search")
    public @ResponseBody ApiResponse<PageResult<DocumentTemplate>> search(@RequestBody @Valid DataViewPageSearch<HashMap> ps) {
        ExtViewHelper.setGroup("DocumentTemplate.search", 1);
        return ApiResponse.make(documentTemplateService.search(ps));
    }

}
